Now that we can display a pattern to the player, and receive their input, we can begin to assemble the game. The first stage of this is a system that can play a single round., i.e. the player sees a sequence then has to repeat it. Once we've got this working, then extending it to play a whole game should be easy.

A single round of the game has two sections, firstly, we must echo the current sequence to the LEDs, then we must check that the user input matches the sequence.

We can display a sequence using the function from Exercise 3.3, and we can get user input using the function from Exercise 3.4.

My first version just plays a single round where the player has to repeat the entire series, and which then tells them either if they've won or lost.

For this test program, I wanted to make sure that if something went wrong, I could easily find out what it was, so I added a system that told me how far through the sequence I was when I pressed the wrong button, and what the wrong button was. I also made sure that for now I'm using a nice easy sequence, so I don't make any silly mistakes and blame it on the program.

My test application is in Exercise 3.5, try it out and look at how easy it'll be to convert it into an entire game.